package com.openbravo.pos.payment;

import com.openbravo.editor.JEditorCurrencyPositive;
import com.openbravo.editor.JEditorKeys;
import com.openbravo.format.Formats;
import com.openbravo.pos.customers.CustomerInfoExt;
import com.openbravo.pos.forms.AppLocal;
import com.openbravo.pos.util.RoundUtils;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIDefaults;
import javax.swing.UIManager;

public class JPaymentPaper extends JPanel
  implements JPaymentInterface
{
  private JPaymentNotifier m_notifier;
  private double m_dTicket;
  private double m_dTotal;
  private String m_sPaper;
  private JLabel jLabel1;
  private JPanel jPanel1;
  private JPanel jPanel11;
  private JPanel jPanel12;
  private JPanel jPanel4;
  private JEditorKeys m_jKeys;
  private JLabel m_jMoneyEuros;
  private JEditorCurrencyPositive m_jTendered;

  public JPaymentPaper(JPaymentNotifier paramJPaymentNotifier, String paramString)
  {
    this.m_notifier = paramJPaymentNotifier;
    this.m_sPaper = paramString;
    initComponents();
    this.m_jTendered.addPropertyChangeListener("Edition", new RecalculateState( ));
    this.m_jTendered.addEditorKeys(this.m_jKeys);
  }

  public void activate(CustomerInfoExt paramCustomerInfoExt, double paramDouble, String paramString)
  {
    this.m_dTotal = paramDouble;
    this.m_jTendered.reset();
    this.m_jTendered.activate();
    printState();
  }

  public Component getComponent()
  {
    return this;
  }

  public PaymentInfo executePayment()
  {
    return new PaymentInfoTicket(this.m_dTicket, this.m_sPaper);
  }

  private void printState()
  {
    Double localDouble = this.m_jTendered.getDoubleValue();
    if (localDouble == null)
      this.m_dTicket = 0.0D;
    else
      this.m_dTicket = localDouble.doubleValue();
    this.m_jMoneyEuros.setText(Formats.CURRENCY.formatValue(new Double(this.m_dTicket)));
    int i = RoundUtils.compare(this.m_dTicket, this.m_dTotal);
    this.m_notifier.setStatus(this.m_dTicket > 0.0D, i >= 0);
  }

  private void initComponents()
  {
    this.jPanel4 = new JPanel();
    this.jLabel1 = new JLabel();
    this.m_jMoneyEuros = new JLabel();
    this.jPanel11 = new JPanel();
    this.jPanel12 = new JPanel();
    this.m_jKeys = new JEditorKeys();
    this.jPanel1 = new JPanel();
    this.m_jTendered = new JEditorCurrencyPositive();
    setLayout(new BorderLayout());
    this.jPanel4.setLayout(null);
    this.jLabel1.setText(AppLocal.getIntString("Label.InputCash"));
    this.jPanel4.add(this.jLabel1);
    this.jLabel1.setBounds(20, 20, 100, 15);
    this.m_jMoneyEuros.setBackground(new Color(153, 153, 255));
    this.m_jMoneyEuros.setHorizontalAlignment(4);
    this.m_jMoneyEuros.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(UIManager.getDefaults().getColor("Button.darkShadow")), BorderFactory.createEmptyBorder(1, 4, 1, 4)));
    this.m_jMoneyEuros.setOpaque(true);
    this.m_jMoneyEuros.setPreferredSize(new Dimension(150, 25));
    this.jPanel4.add(this.m_jMoneyEuros);
    this.m_jMoneyEuros.setBounds(120, 20, 150, 25);
    add(this.jPanel4, "Center");
    this.jPanel11.setLayout(new BorderLayout());
    this.jPanel12.setLayout(new BoxLayout(this.jPanel12, 1));
    this.jPanel12.add(this.m_jKeys);
    this.jPanel1.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    this.jPanel1.setLayout(new BorderLayout());
    this.jPanel1.add(this.m_jTendered, "Center");
    this.jPanel12.add(this.jPanel1);
    this.jPanel11.add(this.jPanel12, "North");
    add(this.jPanel11, "East");
  }

  private class RecalculateState
    implements PropertyChangeListener
  {
    private RecalculateState()
    {
    }

    public void propertyChange(PropertyChangeEvent paramPropertyChangeEvent)
    {
      JPaymentPaper.this.printState();
    }
  }
}

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.payment.JPaymentPaper
 * JD-Core Version:    0.6.0
 */